<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title>编辑分类11</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
  <link rel="stylesheet" href="../../layuiadmin/layui/css/layui.css" media="all">
  <link rel="stylesheet" href="../../layuiadmin/style/admin.css" media="all">
</head>
<body>
  <div style="margin: 20px">
    <div class="basicInfo">
      <div class="record-formtitle">基本信息</div>
      <div class="layui-row form-row">
        <div class="layui-col-md6">
          <div class="layui-form-item">
              <div class="itemTr">站台名称:<span id="stationName"></span></div>
          </div>
          <div class="layui-form-item">
              <div class="itemTr">系统名称:<span id="systemValue"></span></div>
          </div>
          <div class="layui-form-item">
              <div class="itemTr">设备类型:<span id="devTypeValue"></span></div>
          </div>
        </div>
        <div class="layui-col-md6">
          <div class="layui-form-item">
              <div class="itemTr">专业:<span id="specialtyValue"></span></div>
          </div>
          <div class="layui-form-item">
              <div class="itemTr">设备名称:<span id="productName"></span></div>
          </div>
          <div class="layui-form-item">
              <div class="itemTr">维修方式:<span id="maintenanceFlag"></span></div>
          </div>
        </div>
      </div>
    </div>
    <div class="layui-form" lay-filter="planEditForm" id="layuiadmin-form-plan">
      <div class="record-formtitle">更新维修计划</div>
      <div class="layui-row form-row addPlanForm">
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">首次维修计划日期</label>
                <div class="layui-inline">
                    <i class="layui-icon layui-icon-date"></i>
                    <input type="text" name="maintainfirstTime" autocomplete="off" class="layui-input" id="firstRepairDate" style="padding-right: 30px">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">下次维护计划日期</label>
                <div class="layui-inline">
                    <i class="layui-icon layui-icon-date"></i>
                    <input type="text" name="maintainnextTime" autocomplete="off" class="layui-input" id="nextRepairDate">
                </div>
            </div>
            <!-- <div class="layui-form-item">
                <label class="layui-form-label">距离下次维护计划时间(天)</label>
                <div class="layui-inline">
                    <input type="text" name="maintainnextDay" autocomplete="off" class="layui-input" id="mainTainNextDate">
                </div>
            </div> -->
            <div class="layui-form-item">
                <label class="layui-form-label">维修状态:</label>
                <div class="layui-inline">
                    <select name="statu" id="statusList" lay-filter="statusListFilter">
                        <option value="">请选择</option>
                    </select>
                </div>
            </div>
        </div>
        <div class="layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">本次维护计划日期</label>
                <div class="layui-inline">
                    <i class="layui-icon layui-icon-date"></i>
                    <input type="text" name="maintainthisTime" autocomplete="off" class="layui-input" id="thisRepairDate">
                </div>
            </div>
            <div class="layui-form-item">
                <label class="layui-form-label">距离下次维修计划间隔(天)</label>
                <div class="layui-inline">
                    <input type="text" name="intervalDay" autocomplete="off" class="layui-input" disabled id="intervalDay">
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-form-item">
                    <label class="layui-form-label">是否维修计划 </label>
                    <div class="layui-inline">
                        <select name="isPlan" lay-verify="required">
                            <option value="是">是</option>
                            <option value="否">否</option>
                        </select>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <div class="dialog-footer">
        <button class="layui-btn layuiadmin-btn-admin" >取消</button>
        <button class="layui-btn layuiadmin-btn-admin" lay-submit lay-filter="planEditSubmit">确定</button>
      </div>
    </div>
    <div class="record-formtitle">维修记录</div>
    <table id="maintenanceRecord" lay-filter="maintenanceRecord"></table>  
    <div class="layui-form-item layui-hide">
      <input type="button" lay-submit lay-filter="planSubmit" id="planSubmit" value="确定">
  </div> 
  </div>
  <script type="text/html" id="forTaskStatus">
    {{#  if(d.statu == '0'){d.statu = '已恢复'}}
    {{d.statu}}
    {{#  } else if (d.statu == '1'){d.statu = '处理中' }}
    {{d.statu}}
    {{#  } else if (d.statu == '2'){d.statu = '已搁置' }}
    {{d.statu}}
    {{#  } else if (d.statu == '3'){d.statu = '未处理' }}
    {{d.statu}}
    {{#  } else {d.statu = '已处理' }}
    {{d.statu}}
    {{#  } }}
</script>
  <script src="../../layuiadmin/layui/layui.js"></script>  
  <script>
    function initData(data){
      var taskNum = data.taskNum;
      layui.config({
        base: '../../layuiadmin/' //静态资源所在路径
      }).extend({
        index: 'lib/index' //主入口模块
        , my_send: '../myModules/my_send'
      }).use(['index', 'form','laydate','table','my_send'], function () {
        var $ = layui.$
          , form = layui.form
          ,laydate = layui.laydate
          ,table = layui.table
          , my_send = layui.my_send
          , http_proxy = layui.http_proxy;
          //处理状态
          $.ajax({
              type : "get",
              async : false, //异步执行
              url : http_proxy("/devStatus/getStatus"),
              dataType : "json", //返回数据形式为json
              success : function(data) {
                  $.each(data.result,function(index,item){
                      $('#statusList').append(new Option(item.label,item.value));
                  })
                  form.render('select');
              },
              error : function(errorMsg) {
                  alert("请求数据失败");
              }
          });
          $.ajax({
            url:http_proxy('/devStatus/getDomain'),
            async: false,
            dataType:'json',
            type:'get',
            success:function(data){
                $.each(data.result,function(index,item){
                    var laValue = item.label+"#@***#!-"+item.value;
                    $('#majorList').append(new Option(item.label,laValue));
                })
                form.render('select');
            }
          });
          $('#stationName').html(data.stationName);
          $('#systemValue').html(data.systemName);
          $('#productName').html(data.eventName);
          $('#devType').html(data.eventType);
          $('#devTypeValue').html(data.eventType);
          $('#specialtyValue').html(data.doMain);
          $('#maintenanceFlag').html(data.maintainWay === '1' ? '计划维修':'检修');
          $('#maintenanceDate').val(data.maintenanceDate)
          $('#maintenancePersonName').val(data.maintenancePersonName);
          form.val("planEditForm", {
            'maintainfirstTime':data.maintainfirstTime,
            'maintainnextTime':data.maintainnextTime,
            'maintainnextDay':data.maintainnextDay,
            'maintainthisTime':data.maintainthisTime,
            'intervalDay':data.intervalDay,
            'statu':data.statu,
            'isPlan':data.isPlan === '1' ? "是":"否"
          });
          form.render('select');
        //维修记录
        table.render({
          elem: '#maintenanceRecord'
          , url: http_proxy('/alertManager/queryMtRecord?eid=')+data.eid //数据接口
          , page: true //开启分页
          , method: 'post'
          , contentType : "application/json"
          ,parseData:function(res){
            return{
              "code":0
              ,"count":res.total
              ,"data":res.rows
              ,'msg':''
            }
          }
          ,cols: [[
            {field: 'taskNum', title: '工单号'}
            ,{field: 'maintainDate', title: '维修日期'}
            ,{field: 'maintainWay', title: '维修方式'}
            ,{field: 'maintainPerson', title: '维修人',width: 100}
            ,{field: 'maintainContent', title: '维修内容',width: 100}
            ,{field: 'taskStatus', title: '工单状态',width: 100, templet:'#forTaskStatus'}
          ]]
        });
        form.on('submit(planEditSubmit)', function(data){
          var field = data.field; //获取提交的字段
          field.taskNum = taskNum;
          var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引  
          //提交 Ajax 成功后，关闭当前弹层并重载表格
          $.ajax({
              url:http_proxy('/et/maintain/updateMaintain'),
              async: false,
              type:'post',
              contentType:"application/json",
              dataType:'json',
              data:JSON.stringify(field),
              success:function(data){
                debugger
                  if(data.code = "success"){
                    layer.msg(data.message, {icon: 6});
                    parent.layui.table.reload('maintenanceRecord'); //重载表格
                  }else{
                    layer.msg(data.message, {icon: 5});
                  }
              }
          });
            parent.layui.table.reload('maintenanceRecord'); //重载表格
          });
        })
    }
  </script>
</body>
</html>